﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using DTcms.DBUtility;
using DTcms.Common;

namespace DTcms.DAL
{
    /// <summary>
    /// 商品对应规格
    /// </summary>
    public partial class hangqing_price
    {
        public hangqing_price()
        {  
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Model.hangqing_price> GetList(int article_id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select article_id,title,price,is_up,sort_id");
            strSql.Append(" FROM ch_hangqing_price ");
            strSql.Append(" where article_id=" + article_id);
            strSql.Append(" order by sort_id asc,id asc ");
            DataTable dt = DbHelperSQL.Query(strSql.ToString()).Tables[0];
            List<Model.hangqing_price> modelList = new List<Model.hangqing_price>();
            if (dt.Rows.Count > 0)
            {
                for (int n = 0; n < dt.Rows.Count; n++)
                {
                    Model.hangqing_price model = new Model.hangqing_price();
                    if (dt.Rows[n]["article_id"] != null && dt.Rows[n]["article_id"].ToString() != "")
                    {
                        model.article_id = int.Parse(dt.Rows[n]["article_id"].ToString());
                    }
                    if (dt.Rows[n]["title"] != null && dt.Rows[n]["title"].ToString() != "")
                    {
                        model.title = dt.Rows[n]["title"].ToString();
                    }
                    if (dt.Rows[n]["price"] != null && dt.Rows[n]["price"].ToString() != "")
                    {
                        model.price = dt.Rows[n]["price"].ToString();
                    }
                    
                    if (dt.Rows[n]["is_up"] != null && dt.Rows[n]["is_up"].ToString() != "")
                    {
                        model.is_up = int.Parse(dt.Rows[n]["is_up"].ToString());
                    }
                    if (dt.Rows[n]["sort_id"] != null && dt.Rows[n]["sort_id"].ToString() != "")
                    {
                        model.sort_id = int.Parse(dt.Rows[n]["sort_id"].ToString());
                    }
                    modelList.Add(model);
                }
            }
            return modelList;
        }
        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetLists(int Top, string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select");
            if (Top > 0)
            {
                strSql.Append(" top " + Top.ToString());
            }
            strSql.Append(" * from ch_hangqing_price");
            strSql.Append(" where id in(select min(id) from ch_hangqing_price group by article_id)");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" and article_id=(select id from ch_hangqing where " + strWhere + ")");
            }
            return DbHelperSQL.Query(strSql.ToString());
        }
        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ");
            if (Top > 0)
            {
                strSql.Append(" top " + Top.ToString());
            }
            strSql.Append(" id,article_id,title,price,is_up,sort_id");
            strSql.Append(" FROM ch_hangqing_price ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            strSql.Append(" order by " + filedOrder);
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获得指定石材名称的全部价格列表
        /// </summary>
        public DataSet GetAllList(string keywords)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select * from ch_hangqing_price");
            strSql.Append(" where article_id =(select id from ch_hangqing where title='" + keywords + "')");
            return DbHelperSQL.Query(strSql.ToString());
        }
    }
}
